package cn.schoolwow.util.domain.query.resource;

import cn.schoolwow.util.module.query.resource.domain.ResourceQueryOption;
import cn.schoolwow.util.module.query.resource.domain.SingleQueryResourceHandler;

import java.util.Arrays;

public class QueryResource {
    private ResourceQueryOption resourceQueryOption = new ResourceQueryOption();

    /**
     * 创建资源查询对象
     * @param name 资源名称
     * @param path 资源路径
     * */
    public static QueryResource newQuery(String name, String path){
        QueryResource instanceQuery = new QueryResource();
        instanceQuery.resourceQueryOption.name = name;
        instanceQuery.resourceQueryOption.path = path;
        return instanceQuery;
    }

    public QueryResource checkExist(boolean checkExist){
        resourceQueryOption.checkExist = checkExist;
        return this;
    }

    public QueryResource fileName(String fileName){
        resourceQueryOption.fileFilterOption.fileName = fileName;
        return this;
    }

    public QueryResource fileNameStartWith(String... fileNameStartWithArray){
        resourceQueryOption.fileFilterOption.fileNameStartWithList.addAll(Arrays.asList(fileNameStartWithArray));
        return this;
    }

    public QueryResource fileNameEndWith(String... fileNameEndWithArray){
        resourceQueryOption.fileFilterOption.fileNameEndWithList = Arrays.asList(fileNameEndWithArray);
        return this;
    }

    /**遍历时是否忽略文件夹*/
    public QueryResource ignoreDirectory(boolean ignoreDirectory){
        resourceQueryOption.fileFilterOption.ignoreDirectory = ignoreDirectory;
        return this;
    }

    public QueryResource singleQueryResourceHandler(SingleQueryResourceHandler singleQueryResourceHandler){
        resourceQueryOption.fileFilterOption.singleQueryResourceHandler = singleQueryResourceHandler;
        return this;
    }

    public QueryResourceResponse execute(){
        return new QueryResourceResponse(resourceQueryOption);
    }
}
